home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-06-04 | 4.4 KB | 138 lines | [TEXT/MPS ] |
- # **********************************************************************
- # File: Script 2.vu
- #
- # Purpose: to demonstrate screen independence,
- # matching, and list usage
- #
- # Prerequisites: This script assumes that DrawShapesVU is the
- # currently active application on the target.
- #
- # Note: If an attempt is made to draw a shape and
- # the shape does not materialize, it may be
- # because the shape being drawn is smaller than
- # DrawShapeVU's minimum shape size, not because
- # there is a problem with VU.
- #
- # Written by: David Gaxiola
- #
- # Copyright © 1992 by Apple Computer, Inc., all rights reserved.
- #
- # **********************************************************************
-
- # Variables here are globals; that is, they are used
- # throughout the script. They begin with a lowercase g.
-
- # variable definitions:
-
- gToolColumn := 18; # relative x position
- # inside the window
-
- gToolRow := { 40,80,120,160 }; # relative y positions
- # for tools in window
-
- gWindowMod := { 41, 21, -21, -21 }; # Modify position for
- # actual drawing space.
-
- gWindowDim := { }; # Declare empty list
- # for window dimensions.
-
- gScreenDim := { }; # Declare empty list
- # for screen dimensions.
-
- # Begin main body. ***************************************************
-
- MouseSpeed( 10 );
-
- # Get main screen dimensions and put them into a list called
- # "gScreenDim".
- # Note the importance of using ?gScreenDim instead of
- # just gScreenDim. The first puts the dimensions into a
- # variable called gScreenDim. The second would not produce
- # a meaningful result.
-
- match [ screen rectangle:?gScreenDim menubar:true ];
-
- # Create a new work window and manually size it
- # to nearly the screen size.
- #
- # Note how the regular expression /Untitled-≈/ is used
- # to make the selection of the title flexible and how the
- # ordinal o:1 is used to denote the frontmost window.
-
- println "# Setting up new document window.";
- select [ menuItem title:'New' menu:[menu title:'File' ]];
- Wait(2);
- drag [ window title:/Untitled-≈/ o:1 ] a:{ 1, 21 };
- size [ window title:/Untitled-≈/ o:1 ] width:( gScreenDim[3] - 2 )
- height:( gScreenDim[4] - 22 );
-
- # Determine and record the size of the top work window.
-
- match [ window rectangle:?gWindowDim ordinality:1 ];
-
- # Draw a square with random position and size,
- # yet still within the window bounds.
- #
- # Note the use of the built-in task random()
- # as well as the use of lists in the equations.
-
- println "# Performing square drawing operation.";
- move absolute:{ (gWindowDim[1] + gToolColumn),
- (gWindowDim[2] + gToolRow[2])};
- click;
- xStart := Random( (gWindowDim[1] + gWindowMod[1]),
- (gWindowDim[3] + gWindowMod[3]) );
- xStop := Random( (gWindowDim[1] + gWindowMod[1]),
- (gWindowDim[3] + gWindowMod[3]) );
- yStart := Random( (gWindowDim[2] + gWindowMod[2]),
- (gWindowDim[4] + gWindowMod[4]) );
- yStop := Random( (gWindowDim[2] + gWindowMod[2]),
- (gWindowDim[4] + gWindowMod[4]) );
-
- move absolute:{ xStart, yStart };
- pressMouse;
- Wait(1);
- move absolute:{ xStop, yStop };
- releaseMouse;
-
- # Alter window size and update the main gWindowDim.
- # Note the use of the replace built-in task and of
- # list manipulation.
-
- println "# Sizing window.";
- size [ window title:/Untitled-≈/ ordinality:1 ] rectangle:{ -40, 0 };
- match [ window rectangle:?tempDim ordinality:1 ];
- gWindowDim := replace( tempDim[3], 3, gWindowDim );
-
- ### Draw an oval:
-
- println "# Performing oval drawing operation.";
- move absolute:{ (gWindowDim[1] + gToolColumn),
- (gWindowDim[2] + gToolRow[3]) };
- click;
-
- xStart := Random( (gWindowDim[1] + gWindowMod[1]),
- (gWindowDim[3] + gWindowMod[3]) );
- xStop := Random( (gWindowDim[1] + gWindowMod[1]),
- (gWindowDim[3] + gWindowMod[3]) );
- yStart := Random( (gWindowDim[2] + gWindowMod[2]),
- (gWindowDim[4] + gWindowMod[4]) );
- yStop := Random( (gWindowDim[2] + gWindowMod[2]),
- (gWindowDim[4] + gWindowMod[4]) );
-
- move absolute:{ xStart, yStart };
- pressMouse;
- Wait(1); # for slower targets
- move absolute:{ xStop, yStop };
- releaseMouse;
-
- ### Discard the window when finished:
-
- println "# Discarding window.";
- close [ window title:/Untitled-≈/ ordinality:1 ];
- Wait(1); # for slower targets
- select [ button title:'No' window:[ window style:dialog ]];
-
- println "# Finished";
- # End main body. ***************************************************
-